/**
 * Created by Administrator on 2015/3/29.
 */
var mongoUrl = 'mongodb://localhost:27017/mini';
var mongo = require('./mongo');
mongo.connect(mongoUrl, function(){
    console.log('DA Connected to mongo at: ' + mongoUrl);
});

module.exports = {
    weixinUserFind:function(data, callback){
        var coll = mongo.collection("weixinusers");
        coll.find({FromUserName: data.FromUserName}, function ( err, result) {
            callback(err, result)
        });
    },
    applyAdd:function(data, callback){
        var coll = mongo.collection("apply");
        coll.insert(data, function (err, result) {
            callback(err, result);
        });
    },
    weixinUserUpdate: function (data, upsert, callback) {
        var coll = mongo.collection("weixinusers");
        coll.update({FromUserName: data.FromUserName}, data, upsert, function(err, result){
            callback(err, result);
        });
    },
    linkUpdate: function (data, upsert, callback) {
        var coll = mongo.collection("links");
        coll.update({FromUserName: data.FromUserName, Url:data.Url}, data, upsert, function(err, result){
            callback(err, result);
        });
    }
};